#include "ExternGlobals.h"

short Ids_filter(short input);

// ========================================================================
// 函数名称：Ids_filter()
// 输入参数：input
// 输出参数：result
// 扇    入：无
// 扇    出：无
// 函数描述：这是相电流的均值滤波算法，将采集到的128个电流值，求取其平均值
// ========================================================================


short Ids_filter(short input)
{
    static int   sum = 0;
    static short buffer[128];
    static short point_a1 = 0;
    static short flag1 = 0;
    short reslut = 0;
    short temp = buffer[point_a1];
    sum = sum + input;
    buffer[point_a1] = input;
    point_a1++;

    if(flag1 == 0)
    {
        reslut = (short)(sum / point_a1);//未满128个采样点
        if(point_a1 >= 128)          
        {
            flag1 = 1;
            point_a1 = 0;
        }
    }
    else  //满128个采样点
    {
        sum = sum - temp;
        reslut = (short)(sum / 128);

        if(point_a1 >= 128)
            point_a1 = 0;
    }

    return reslut;
}
